/* << fastinsert report library >> Debug.h Oct 31, 2010
 *
 * 	http://code.google.com/p/libfir
 *
 * Copyright (c) 2005 Pavlo Drobov (drobov.pavel@gmail.com)
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 */


#ifndef DEBUG_H_
#define DEBUG_H_

#ifndef MAX
#define MAX(a, b) (a > b ? a : b)
#endif
#ifndef MIN
#define MIN(a, b) (a < b ? a : b)
#endif

#include "win32_export_macros.h"


//mark depricated method
#define DEPRICATED


#include <iostream>
#include <string>


//define my data type
typedef unsigned char __u8;
typedef unsigned short __u16;
typedef unsigned int __u32;
typedef unsigned long   __u64;
typedef long int __bigint;
//typedef float __realpg;


////////////////// linux console Escape charcater
#define TAB "\t"
#define RN "\r\n"

#define GREEN 	"\033[0;32m"
#define RED 	"\033[0;31m"
#define WHITE0	"\033[0;37m"
#define WHITE1	"\033[1;37m"

#define DEBUG  Debug::getInstance()
#define ENDL   "\n"

#ifndef RELEASE
#define DEBUG_MSG(msg) DEBUG << "@" << __FILE__ << ":"<<__LINE__ << ">>>\n\t" <<  msg << ENDL
#define DEBUG_IF_MSG(b,msg)  \
		if(b) DEBUG << msg << ENDL
#else
#define DEBUG_MSG(msg)
#define DEBUG_IF_MSG(b,msg)
#endif

#define STRUCT_TM_DEBUG(tm) \
	DEBUG_MSG(\
			"Year: " << tm.tm_year << \
			";\tMonth: " << tm.tm_mon <<  \
			";\tDay: " << tm.tm_mday <<  \
			";\tHour: " << tm.tm_hour <<  \
			";\tMin: " << tm.tm_min <<  \
			";\tSec: " << tm.tm_sec <<  \
			";\tWday: " << tm.tm_wday <<  \
			";\tYday: " << tm.tm_yday   \
			)



#define LOG(msg) DEBUG << Debug::getInstance().getCurrentFormatTime()  << "\t" << msg << ENDL
#define LOG_RED(msg) DEBUG << RED << Debug::getInstance().getCurrentFormatTime()  << "\t" << msg << WHITE0<< ENDL
#define LOG_GREEN(msg) DEBUG << GREEN << Debug::getInstance().getCurrentFormatTime()  << "\t" << msg << WHITE0<< ENDL

typedef unsigned long llu;

#define REVISION 	Debug::getRevision()

//! \class Debug
//!	\brief trace utility
class DLL_EXPORT Debug
{
public:
	virtual ~Debug();

	Debug& operator <<(const int);
	Debug& operator <<(const float);
	Debug& operator <<(const __u32);
	Debug& operator <<(const __u64);
	Debug& operator <<(const __bigint);
	Debug& operator <<(const char*);
	Debug& operator <<(const bool);
	Debug& operator <<(const std::string&);

	void endl();

	static std::string getCurrentTime();
	static std::string getCurrentFormatTime();

	static std::string parseSvnIdKeyword(const char*);
	static std::string ip2str(unsigned int);


	static Debug* getInstanceRef(std::ostream* = &std::cout);
	static Debug& getInstance(std::ostream* = &std::cout);
	static Debug& getInstance(const char*);


private:
	Debug(std::ostream*);
	std::ostream *out;

	static Debug * Instance;
};

#endif /*DEBUG_H_*/
